<?php

namespace app\index\controller;
use app\index\controller\Common;

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

class Mailer extends Common
{
	public function index()
	{
		$mail = new PHPMailer(true);
		try {
			//Server settings
			$mail->CharSet      = "UTF-8";                               //设定邮件编码
			$mail->SMTPDebug    = SMTP::DEBUG_SERVER;                   // Enable verbose debug output
			$mail->isSMTP();                                            // Send using SMTP
			$mail->Host       = 'smtp.163.com';                         // Set the SMTP server to send through
			$mail->SMTPAuth   = true;                                   // Enable SMTP authentication
			$mail->Username   = '13433159407@163.com';                       // SMTP username
			$mail->Password   = 'chenxl123';                             // SMTP password 授权码

			$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            // Enable TLS encryption;
			// `PHPMailer::ENCRYPTION_SMTPS` also accepted
			//$mail->SMTPSecure = 'ssl';

			$mail->Port       = 465;                                    // TCP port to connect to

			//Recipients
			$mail->setFrom('13433159407@163.com', '陈旭良');

			$mail->addAddress('844745054@qq.com', '你好');        // Add a recipient
			//$mail->addAddress('ellen@example.com');                               // Name is optional

			$mail->addReplyTo('13433159407@163.com', '陈旭良');        //回复的时候回复给哪个邮箱 建议和发件人一致

			$mail->addCC('2832288348@qq.com');       //抄送
			//$mail->addBCC('bcc@example.com');     //密送

			// Attachments 附件
			//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
			//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

			// Content
			$mail->isHTML(true);                                  // Set email format to HTML
			//				$mail->Subject = 'Here is the subject';
			//				$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
			//				$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

			$mail->Subject = '加油吧骚年';
			$mail->Body    = '<b style="color:red;">测试</b>';
			$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

			$mail->send();
			echo '邮件发送成功!';
			//return $this->success('发送邮件成功', '/');
		} catch (Exception $e) {
			echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
			//return $this->error('发送邮件失败'.$mail->ErrorInfo);
		}
	}
}
